﻿using System;
using System.Collections.Generic;
using System.Text;
using DTcms.Common;
using System.Data;

namespace DTcms.Web.UI.Page
{
    public partial class index : Web.UI.BasePage
    {
        protected int navId = 1;
        //
        protected string channelsString = string.Empty;
        protected string subChannelsString = string.Empty;

        protected DataTable firstNavigations = new DataTable();
        /// <summary>
        /// 重写虚方法,此方法将在Init事件前执行
        /// </summary>
        protected override void ShowPage()
        {
            DataSet siteChannel = new BLL.site_channel().GetList(4,"is_lock=0","sort_id asc");
            DataSet subChannels = new DataSet();
            if (siteChannel != null && siteChannel.Tables[0].Rows.Count > 0)
            {
                DataTable dtSiteChannels = siteChannel.Tables[0];
                StringBuilder channelSB = new StringBuilder();
                StringBuilder subChannlesSB = new StringBuilder();
                for (int i=0; i < dtSiteChannels.Rows.Count; i++)
                {
                    
                    if (i > 0)
                    {
                        subChannlesSB.Append("</ul></div>\n");
                    }

                    string channelName = dtSiteChannels.Rows[i]["name"].ToString();
                    //获取子频道内容
                    DataTable subCategory = get_category_child_list(channelName,0);
                    if (i + 1 == 1)
                    {
                        string li = string.Format("<li class=\"active\"><a href=\"#server_item{0}\" data-toggle=\"tab\">{1}</a></li>\n",i+1, dtSiteChannels.Rows[i]["title"]);
                        string ul = string.Format(" <div class=\"server_item fade active in\" id=\"server_item{0}\"><ul>\n",i+1);
                        channelSB.Append(li);
                        subChannlesSB.Append(ul);
                    }
                    else 
                    {
                        string li = string.Format("<li><a href=\"#server_item{0}\" data-toggle=\"tab\">{1}</a></li>\n",i+1, dtSiteChannels.Rows[i]["title"]);
                        channelSB.Append(li);
                        string ul = string.Format(" <div class=\"server_item tab-pane\" id=\"server_item{0}\"><ul>\n", i + 1);
                        subChannlesSB.Append(ul);
                    }
                    
                   
                    for (int j = 0; j < subCategory.Rows.Count; j++)
                    {
                        subChannlesSB.Append("<li>\n");
                        if (!string.IsNullOrEmpty(subCategory.Rows[j]["link_url"].ToString()))
                        {
                            string link = string.Format("<a href=\"{0}\">\n", subCategory.Rows[j]["link_url"]);
                            subChannlesSB.Append(link);
                        }
                        else 
                        {
                            int subChannelId = int.Parse(subCategory.Rows[j]["id"].ToString());
                            string url = linkurl(channelName+"_list",subChannelId);
                            string link = string.Format("<a href=\"{0}\">\n", url);
                            subChannlesSB.Append(link);
                        }
                        string cssStr = string.Format("<i class=\"icon {0}\"></i>\n",subCategory.Rows[j]["img_url"]);
                        subChannlesSB.Append(cssStr);
                        string nameStr = string.Format("<span>{0}</span>\n", subCategory.Rows[j]["title"]);
                        subChannlesSB.Append(nameStr);
                        subChannlesSB.Append("</a></li>\n");   
                    }
                                     
                }
                subChannlesSB.Append("</ul></div>");  
                //大分类拼接完成
                channelsString = channelSB.ToString();
                subChannelsString= subChannlesSB.ToString();

            }   
        }
    }

}
